package View;

import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.image.WritableImage;
import javafx.scene.paint.Color;
import javafx.stage.StageStyle;

import java.io.IOException;

public class LoginWindow extends window{
    private boolean flag=false;
    public LoginWindow() throws IOException {
        root = FXMLLoader.load(getClass().getResource("/Fxml/login.fxml"));
        Scene scene = new Scene(root, 600, 400);
        scene.setFill(Color.TRANSPARENT);
        setScene(scene);
        initStyle(StageStyle.TRANSPARENT);
        setResizable(false);
        setTitle("We Chat");
        Image image=new Image("/Picture/sourceMaterial/登录背景图.jpg",612,400,false,false);
        ((ImageView)$("backgroundImage")).setImage(image);
        move();
        setIcon();
        quit();
        minimiser();
    }

    public boolean isFlag() {
        return flag;
    }

    public void setFlag(boolean flag) {
        this.flag = flag;
    }

    //退出
    @Override
    public void quit() {
        ((Button) $("exitButton")).setTooltip(new Tooltip("退出"));
        ((Button) $("exitButton")).setOnAction(event -> {
            close();
            System.exit(0);
        });

    }
    //最小化
    @Override
    public void minimiser() {
        ((Button) $("ministerButton")).setTooltip(new Tooltip("最小化"));
        ((Button) $("ministerButton")).setOnAction(event -> {
            setIconified(true);
        });
    }
    //错误提示
    public void setErrorTip(String id,String Text){
        ((Label) $(id)).setText(Text);
    }
    //重置错误提示
    public void resetErrorTip(){
        setErrorTip("actTip", "");
        setErrorTip("pswTip", "");
    }
    //清除各种输入框
    public void clear(){

        ((TextField) $("actText")).clear();
        ((PasswordField) $("pswText")).clear();
    }
    public void clear(String id){

        ((TextField) $(id)).clear();
    }

}
